package system

import (
	"context"
	"fmt"
	"time"

	"github.com/gin-gonic/gin"
	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
)

// Userinfo
// @Summary get_img
// @Description get_img
// @Tags get_img
// @Accept json
// @Produce json
// @Success 200 {string}  string "success"
// @Failure 400 {string} string "bad request"
// @Failure 500 {string} string "Internal Server Error"
// @Router /get_img [get]
func GetImg(c *gin.Context) {

	endpoint := "127.0.0.1:9000"
	accessKeyID := "ZVF8VV2KKWH687VZ41MY"
	secretAccessKey := "Vya75gyOQmAWnNKVkuLvwendrpaJDswK0LinK"
	useSSL := false
	// endpoint := "play.min.io"
	// accessKeyID := "Q3AM3UQ867SPQQA43P2F"
	// secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
	// useSSL := true

	// Initialize minio client object.

	// input_path, err := storage.COSUpload(avatar_byte, avatar.Filename, "zzz", "png")
	// fmt.Printf("=========%s-%s\n", err, input_path)

	// out_data, err := storage.COSGetFile("zzz/20241115114705984529.png")
	// fmt.Println("---", err)
	// fmt.Printf("===%T", out_data)
	// out, err := os.Create("./image.jpg")
	// if err != nil {
	// 	panic(err)
	// }
	// defer out.Close()
	// // 将响应体的内容写入到文件中
	// _, err = io.Copy(out, out_data)

	// url_data, err := storage.COSGetURL("zzz/20241115114705984529.png")
	// fmt.Printf("%s--%s\n", err, url_data)

	// err = storage.COSDelFile("zzz/20241115114705984529.png")
	// fmt.Println("==", err)

	// ------------------------------------------------------

	// input_path, err := storage.MinioUpload(avatar_byte, "qazwsx.png", "zzz", "")
	// fmt.Printf("=========%s-%s", err, input_path)

	// url_data, err := storage.MinioGetURL("zzz/20241114151657989536.png")
	// fmt.Printf("%s--%s\n", err, url_data)

	// err = storage.MinioDelFile("zzz/20241114151657989536.png")
	// fmt.Println("==", err)

	minioClient, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
		Secure: useSSL,
	})
	if err != nil {
		fmt.Println(err)
	}

	presignedURL, err := minioClient.PresignedGetObject(context.Background(), "media", "zzz/20241114151657989536.png", time.Second*24*60*60, nil)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("Successfully generated presigned URL", presignedURL)

	c.String(200, "ok")

}
